package com.sfx.concurrent.demo.concurrent.pattern.MessageQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-01
 * Time: 12:08
 */

public class TestMain {
    public static void main(String[] args) throws InterruptedException {
        MessageQueue queue = new MessageQueue(2);
        //生产者线程
        for(int i =0;i<3;++i) {
            int id = i;
            new Thread(()->{
                queue.take(new Message(id,"message" + id));
            },"生产者" + i).start();
        }
        Thread.sleep(1000);
        //消费者线程-->消费者不断地消费
        new Thread(()->{
            while(true) {
                Message message = queue.get();
            }
        },"消费者").start();
    }
}